#include "FuzeStdafx.h"
#include "stdafx.h"

#include <gtest/gtest.h>
#include "Bus/ChipBus.h"
#include "Register/VCR.h"

class VCRTest : public testing::Test
{
public:
	virtual void SetUp()
	{
		m_hQuit = ::CreateEvent(NULL,TRUE,FALSE,NULL);
		m_chipBusSet.clear();
	}

	virtual void TearDown()
	{
	}

	void CreateChipBusSet()
	{	
		static ChipBus::ChipBusPtr ctpExternalQueue(ChipBus::Create(m_hQuit));
		m_chipBusSet.insert(pair<Exchange::FLAG, ChipBus::ChipBusPtr>(Exchange::CTP, ctpExternalQueue));
		ChipMessage message = {0};
		message.type = ChipMessage::LOGIN;
		ctpExternalQueue->Push(message);

		static ChipBus::ChipBusPtr dceExternalQueue(ChipBus::Create(m_hQuit));
		m_chipBusSet.insert(pair<Exchange::FLAG, ChipBus::ChipBusPtr>(Exchange::DCE, dceExternalQueue));
		message.type = ChipMessage::ORDER_INSERT;
		dceExternalQueue->Push(message);
	}

private:
	HANDLE m_hQuit;
public:
	ChipBusSet m_chipBusSet;
};


TEST_F(VCRTest, GetChipBusTest)
{
	CreateChipBusSet();

	bool quitFlag = false;
	ChipMessage const dceMessge = (*(m_chipBusSet[Exchange::DCE].get())).Pop(quitFlag);
	EXPECT_EQ(dceMessge.type, ChipMessage::ORDER_INSERT);

	ChipMessage const ctpMessge = (*(m_chipBusSet[Exchange::CTP].get())).Pop(quitFlag);
	EXPECT_EQ(ctpMessge.type, ChipMessage::LOGIN);
}